package Commands;

import domain.Controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class CmdGendan extends Command
{
  protected String nextJspUrl = 
    "userStory4.jsp"; 
  CommandFactory comFac;
  Controller controller;

  public void init(CommandFactory comFac, Controller c)
    throws ServletException 
  {
    this.comFac = comFac;
    this.controller = c;
  }

  public void execute(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException 
  {
    System.out.println("Gendan");
    HttpSession session = req.getSession();
    nextJspUrl = req.getParameter("ref") + ".jsp";
    controller.clearPuljer();
    session.removeAttribute("pulje1");
    session.removeAttribute("pulje2");
    controller.getPuljer();
    session.setAttribute("pulje1",controller.getPulje1());
    session.setAttribute("pulje2",controller.getPulje2()); 
    session.setAttribute("subjects",controller.getAllSubjects());
    controller.checkPuljer();
    session.setAttribute("students",controller.getStudents());
  }
  
  public String getNextJspUrl()
  {
    return nextJspUrl;
  }
}
